﻿using ProjectManager.Logic.Content;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectManager.UnderLogic
{
    internal static class InfoToDataTable
    {
        public static DataTable ToDataTable(this ProjectTaskInformation taskInformation)
        {
            // (ID, TeamID, BranchName, Name, Description, protectedPaths, StartDate, EndDate, Status, ChildTasks)
            DataTable dt = new();
            dt.Columns.Add("ID", typeof(int));
            dt.Columns.Add("TeamID", typeof(int));
            dt.Columns.Add("BranchName", typeof(string));
            dt.Columns.Add("Path", typeof(string));
            dt.Columns.Add("Name", typeof(string));
            dt.Columns.Add("Description", typeof(string));
            dt.Columns.Add("protectedPaths", typeof(List<string>));
            dt.Columns.Add("StartDate", typeof(DateTime));
            dt.Columns.Add("EndDate", typeof(DateTime));
            dt.Columns.Add("Status", typeof(ProjectTaskStatus));
            dt.Columns.Add("ChildTasks", typeof(List<int>));
            dt.Rows.Add(taskInformation.ID, taskInformation.TeamID, taskInformation.BranchName
                , taskInformation.Path, taskInformation.Name
                , taskInformation.Description, taskInformation.protectedPaths
                , taskInformation.StartDate, taskInformation.EndDate
                , taskInformation.Status, taskInformation.ChildTask.Select(x => x.ID).ToList());
            return dt;
        }
        public static DataTable ToDataTable(this TeamInformation teamInformation)
        {
            // (ID, Name, Leader, Members, Tasks, IsIndividual, IsCancelled)
            DataTable dt = new();
            dt.Columns.Add("ID", typeof(int));
            dt.Columns.Add("Name", typeof(string));
            dt.Columns.Add("Leader", typeof(MemberInformation));
            dt.Columns.Add("Members", typeof(List<int>));
            dt.Columns.Add("Tasks", typeof(List<int>));
            dt.Columns.Add("IsIndividual", typeof(bool));
            dt.Columns.Add("IsCancelled", typeof(bool));
            if (teamInformation.Name == null)
            {
                throw new Exception();
            }
            dt.Rows.Add(teamInformation.ID, teamInformation.Name
                , teamInformation.Leader
                , teamInformation.Members.Select(x => x.ID).ToList()
                , teamInformation.Tasks.Select(x => x.ID).ToList()
                , teamInformation.IsIndividual, teamInformation.IsCancelled);
            return dt;
        }
    }
}
